#include "updatewidge.h"
#include "ui_updatewidge.h"
#include "QSqlQuery"
#include "QMessageBox"
#include "QDebug"
UpdateWidge::UpdateWidge(QString userName,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UpdateWidge)
{
    ui->setupUi(this);
    ui->UserNameInput->setText(userName);
    ui->UserNameInput->setEnabled(false);
}
UpdateWidge::~UpdateWidge()
{
    delete ui;
}

void UpdateWidge::on_ConfirmBtn_clicked()
{
    QString userName=ui->UserNameInput->text();
    QString passWord=ui->PsdInput->text();
    QSqlQuery request;
    request.prepare("select username from user where username=?");
    request.addBindValue(userName);
    request.exec();
    request.next();
    if(request.value(0).toString()==userName)
    {
        request.prepare("update user set password=? where username=?");
        request.addBindValue(passWord);
        request.addBindValue(userName);
        int status=request.exec();
        if(status)
        {
            QMessageBox::warning(this,"Notify","User："+userName+" update success!");
            emit sendData();
        }
    }
    else
    {
        QMessageBox::warning(this,"Error","The User:"+userName+" isn't exist!");
    }
}
